﻿namespace CommonData.Util.String
{
    using System;
    using System.Runtime.CompilerServices;

    public static class StringExtension
    {
        public static string FirstToLower(this string target, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new NullReferenceException("this value is null");
            }
            if (value.Length == 1)
            {
                return value.ToLower();
            }
            return (value.Substring(0, 1).ToLower() + value.Remove(0, 1));
        }

        public static string FirstToUpper(this string target, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new NullReferenceException("this value is null");
            }
            if (value.Length == 1)
            {
                return value.ToUpper();
            }
            return (value.Substring(0, 1).ToUpper() + value.Remove(0, 1));
        }

        public static string LastToUpper(this string target, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new NullReferenceException("this value is null");
            }
            if (value.Length == 1)
            {
                return value.ToUpper();
            }
            return (value.Remove(value.Length - 1, 1) + value.Substring(value.Length - 1, 1).ToUpper());
        }
    }
}

